<template>
  <div>
    <el-table :data="reservationList" border style="width:100%">
      <el-table-column type="index" label="ID" width="50"></el-table-column>
      <el-table-column prop="type" label="预约类型" width="80">
        <template slot-scope="scope">{{showType(scope.row)}}</template>
      </el-table-column>
      <el-table-column prop="memberName" label="预约人姓名"></el-table-column>
      <el-table-column prop="petName" label="选择宠物"></el-table-column>
      <el-table-column prop="appointment" label="预约时间"></el-table-column>
      <el-table-column prop="user_phone" label="联系电话"></el-table-column>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button @click="info(scope.row)" size="mini" class="text-center">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="margin-top-20 text-center" v-if="reservationList.length">
      <el-pagination
        @size-change="pageSizeChange"
        @current-change="currentPageChange"
        :background="true"
        :current-page="page.currentPage"
        :page-sizes="[10, 20, 30]"
        :page-size="page.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      reservationList: [],
      page: {
        total: 0,
        currentPage: 1,
        size: 10
      }
    };
  },
  props: ["petId"],
  mounted() {
    let pid = this.petId;
    this.getReservationListDataByPetId(pid);
  },
  methods: {
    getReservationListDataByPetId(pid) {
      this.axios
        .get(
          "/inquiry/listPetInquiry/" +
            pid +
            "/" +
            this.page.size +
            "/" +
            this.page.currentPage,
          {}
        )
        .then(response => {
          if (response.data.code == 200) {
            this.reservationList = response.data.data.data;
            this.page.total = response.data.data.total;
          } else {
            this.$message({
              message: "数据加载失败!",
              type: "error"
            });
          }
        });
    },

    back() {
      this.$router.go(-1);
    },
    info(row) {
      this.$router.push({
        name: "ReservationInfo",
        params: { id: row.id, type: row.type }
      });
    },
    pageSizeChange(val) {
      this.page.currentPage = 1;
      this.page.size = val;
      this.getReservationListDataByPetId(this.petId);
    },
    currentPageChange(val) {
      this.page.currentPage = val;
      this.getReservationListDataByPetId(this.petId);
    },
    showType(row) {
      switch (row.type) {
        case 1:
          return "在线挂号";
        case 2:
          return "体检预约";
        case 3:
          return "免疫预约";
        case 4:
          return "转诊";
        default:
          return "无";
      }
    }
  }
};
</script>
